package com.gouqi.mall.mapper;

import com.gouqi.mall.domain.ProductBrand;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductBrandMapper {
    //@Results({
    //    @Result(property = "id", column = "id"),
    //    @Result(property = "name", column = "name"),
    //    @Result(property = "founder", column = "founder")
    //})
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("INSERT INTO product_brand(founder, cellphone,telephone,product_address,brand_trademark,trademark,name,regis_time,regis_address,business_license,food_safety_permit,takeoff,takeoff_time,takeoff_reason,approval)" +
            "VALUES(#{founder}, #{cellphone}, #{telephone}, #{productAddress}, #{brandTradeMark},#{tradeMark},#{name},#{registerTime},#{registerAddress},#{businessLicense},#{foodSafetyPermit},#{takeoff},#{takeoffTime},#{takeoffReason},#{approval})")
    Integer addOneBrand(ProductBrand brand);

    @Update("update product_brand " +
            "set founder=#{founder}, cellphone=#{cellphone},telephone=#{telephone},product_address=#{productAddress},brand_trademark=#{brandTradeMark},trademark=#{tradeMark},name=#{name}," +
            "regis_time=#{registerTime},regis_address=#{registerAddress},business_license=#{businessLicense},food_safety_permit=#{foodSafetyPermit},takeoff=#{takeoff},takeoff_time=#{takeoffTime},takeoff_reason=#{takeoffReason},approval=#{approval}" +
            "where id=#{id}")
    Integer updateOneBrand(ProductBrand brand);

    @Select("select * from product_brand order by id limit #{index},#{pageSize}")
    List<ProductBrand> queryAllBrands(@Param(value = "index") Integer index,@Param(value = "pageSize") Integer pageSize);

    @Select("select count(*) from product_brand")
    Integer queryCountBrand();

    @Select("select * from product_brand order by id limit 0,10")
    List<ProductBrand> queryRankBrand(@Param(value = "type") String type);

    @Delete("delete from product_brand where id=#{id}")
    Integer deleteOneBrand(@Param(value = "id") Integer id);

    @Update("update product_brand set takeoff=#{takeoff},takeoff_time=#{takeoffTime},takeoff_reason=#{takeoffReason} where id=#{id}")
    Integer takeoffOneBrands(@Param(value = "id") Integer id, @Param(value = "takeoff") Boolean takeoff, @Param(value = "takeoffTime") String takeoffTime, @Param(value = "takeoffReason") String takeoffReason);
}
